{% extends "journal/base.html" %}

{% block has_messages %}
{% endblock has_messages %}

{% block main %}
<section>
    <h1>注册</h1>
    {% if messages %}
    <section>
    <ul class="messages">
        {% for message in messages %}
        <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
        {% endfor %}
    </ul>
    </section>
    {% endif %}
    <form method="post" novalidate>
        {% csrf_token %}
        <label for="phone_number">手机号：
            <input type="tel" 
                   name="phone_number" 
                   id="phone_number" 
                   required
                   pattern="[0-9]{11}"
                   value="{{ form.phone_number.value|default:'' }}"
                   placeholder="请输入11位手机号">
            {% if form.phone_number.errors %}
            <span class="error">{{ form.phone_number.errors.0 }}</span>
            {% endif %}
        </label>
        
        <label for="nickname">昵称：
            <input type="text" 
                   name="nickname" 
                   id="nickname" 
                   required 
                   value="{{ form.nickname.value|default:'' }}"
                   placeholder="请输入昵称">
            {% if form.nickname.errors %}
            <span class="error">{{ form.nickname.errors.0 }}</span>
            {% endif %}
        </label>
        
        <label for="password1">密码：
            <input type="password" 
                   name="password1" 
                   id="password1" 
                   required
                   placeholder="请输入密码">
            {% if form.password1.errors %}
            <span class="error">{{ form.password1.errors.0 }}</span>
            {% endif %}
        </label>
        
        <label for="password2">确认密码：
            <input type="password" 
                   name="password2" 
                   id="password2" 
                   required
                   placeholder="请再次输入密码">
            {% if form.password2.errors %}
            <span class="error">{{ form.password2.errors.0 }}</span>
            {% endif %}
        </label>
        
        {% if not invite_code %}
        <label for="invite_code">邀请码：
            <input type="text" 
                   name="invite_code" 
                   id="invite_code" 
                   required
                   value="{{ form.invite_code.value|default:invite_code|default:'' }}"
                   placeholder="请输入邀请码">
            {% if form.invite_code.errors %}
            <span class="error">{{ form.invite_code.errors.0 }}</span>
            {% endif %}
        </label>
        {% else %}
        <input type="hidden" name="invite_code" value="{{ invite_code }}">
        {% endif %}
        
        <button type="submit">注册</button>
    </form>
    
    <div class="form-footer">
        <p>已有账号？ <a href="{% url 'login' %}">立即登录</a></p>
    </div>
</section>
{% endblock %} 